                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                function utype Formatter(value, row, index) {
            if (value == undefined || value == "") return "";
                                                                            else if(value ==1)
                        return "会员级";
                                        else if(value ==2)
                        return "商家类";
                                        else if(value ==3)
                        return "代理类";
                                        else if(value ==4)
                        return "导购";
                                        else if(value ==5)
                        return "平台";
                                        else if(value ==6)
                        return "接单员";
                                                else return ""
        }
                                                                                    $("#mfilegphotos").fileinput({
            showPreview: true,
            showUpload: true,
            elErrorContainer: '#kartik-file-errors',
            uploadUrl: '/admin/upload/file?type=usermp',
            allowedFileExtensions: ["jpg", "jpeg", "png", "gif"]
        }).on("fileuploaded", function (event, data) {
            console.log(data);
            $("#hidgphotos").val(data.response.data);
        })
                                                                                                                                                                                                        
function changeState(id, state) {
    $.ajax({
        type: 'POST',
        url: "changeState",
        data: {
            id: id,
            state: state
        },
        success: function () {
            $('#mytable').bootstrapTable('refresh', {url: '/admin/usermp/list'});
        },
        dataType: "json"
    });
}

function deleteOne(id) {
    swal({
        title: '您确定要删除此行数据？',
        text: '你将无法恢复它！',
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#ed5666',
        confirmButtonText: '确定删除！',
        cancelButtonText: '取消删除！',
        confirmButtonClass: 'btn btn-success',
        cancelButtonClass: 'btn btn-danger',
        buttonsStyling: false
    }).then(function () {

        $.ajax({
            type: 'POST',
            url: "deleteOne",
            data: {
                id: id,
            },
            success: function (status) {
                if (status == 1) {
                    swal({title: "删除成功", text: "", type: "success"})
                    $('#mytable').bootstrapTable('refresh', {url: '/admin/usermp/list'});
                } else {
                    swal({title: "删除失败", text: "", type: "error"})
                }
            },
            dataType: "json"
        });

    }, function (dismiss) {
        // dismiss的值可以是'cancel', 'overlay',
        // 'close', 'timer'
        if (dismiss === 'cancel') {
            swal({title: '您已取消操作！', text: '', timer: 2000})
        }
    })
}

var editsw = [];

/**
 * 为模态框填充数据
 */
$('#modal-form').on('show.bs.modal', function (event) {
    var button = $(event.relatedTarget); // 触发事件的按钮
    var index = button.data('index');
    var modal = $(this);
    var data = $('#mytable').bootstrapTable("getData")[index]
    console.log(data)

                        modal.find('#id').val(data.id)
                                                    modal.find('#name').val(data.name)
                                editsw["hasmp"] == undefined ? editsw["hasmp"] = new Switchery(document.querySelector('#hasmp'), {color: "#1AB394"}) : ""
            if (data.hasmp == 1) {
                setSwitchery(editsw["hasmp"], true);
            } else {
                setSwitchery(editsw["hasmp"], false);
            }
                                modal.find('#nickName').val(data.nickName)
                                modal.find('#avatarPic').val(data.avatarPic)
                                modal.find('#addr').val(data.addr)
                                modal.find('#address').val(data.address)
                                modal.find('#language').val(data.language)
                                modal.find('#company').val(data.company)
                                modal.find('#depart').val(data.depart)
                                modal.find('#gslogo').val(data.gslogo)
                                modal.find('#hangye').val(data.hangye)
                                modal.find('#hangyeid').val(data.hangyeid)
                                modal.find('#gs').val(data.gs)
                                modal.find('#duty').val(data.duty)
                                modal.find('#zhichen').val(data.zhichen)
                                modal.find('#skill').val(data.skill)
                                modal.find('#resource').val(data.resource)
                                modal.find('#phone').val(data.phone)
                                modal.find('#tphone').val(data.tphone)
                                modal.find('#telphone').val(data.telphone)
                                modal.find('#email').val(data.email)
                                modal.find('#qq').val(data.qq)
                                modal.find('#weixinimg').val(data.weixinimg)
                                modal.find('#weixin').val(data.weixin)
                                modal.find('#weibo').val(data.weibo)
                                modal.find('#jifen').val(data.jifen)
                                modal.find('#photo').val(data.photo)
                                modal.find('#guid').val(data.guid)
                                modal.find('#utype').find("option[value='" + data['utype'] + "']").attr("selected", true);
                                modal.find('#beiso').val(data.beiso)
                                modal.find('#gongkai').val(data.gongkai)
                                modal.find('#ip').val(data.ip)
                                modal.find('#gids').val(data.gids)
                                // 此部分需要注意：如果页面有两个以上的图片编辑
            $("#mfilegphotos2").fileinput('destroy');
            $("#mfilegphotos2").fileinput({
                showPreview: true,
                showUpload: true,
                append: true,overwriteInitial:false,
                uploadClass: "btn btn-info",
                uploadLabel: "上传",removeLabel: "移除",language: "zh",
                uploadIcon: "<i class=\"glyphicon glyphicon-upload\"></i> ",
                initialPreviewShowDelete: true,
                initialPreviewAsData: true,
                initialPreviewFileType: 'image',
                initialPreview: getPreviewList(data.gphotos),
                previewFileIcon: '<i class="fa fa-file"></i>',
                allowedPreviewTypes: ['image'],
                initialPreviewConfig: getPreviewConfig(data.gphotos, 'usermp', "gphotos", data.id),
                elErrorContainer: '#kartik-file-errors',
                uploadUrl: '/admin/upload/file?type=usermp',
                allowedFileExtensions: ["jpg", "jpeg", "png", "gif"]
            }).on("fileuploaded", function (event, data) {
                console.log(data);
                $("#hidgphotos2").val(data.response.data + ";" + $("#hidpic2").val());
            }).on('filedeleted', function(event, key, jqXHR, data) {
                console.log('Key = ' + key);
                $("#hidgphotos2").val(filedeleted($("#hidgphotos2").val(),key));
            })
            $("#hidgphotos2").val(data.gphotos)
                                modal.find('#vedio').val(data.vedio)
                                modal.find('#audio').val(data.audio)
                                modal.find('#signature').val(data.signature)
                                modal.find('#latitude').val(data.latitude)
                                modal.find('#longitude').val(data.longitude)
                                modal.find('#mpimg').val(data.mpimg)
                                modal.find('#mpclass').val(data.mpclass)
                                modal.find('#mptype').find("option[value='" + data['mptype'] + "']").attr("selected", true);
                                modal.find('#mpid').val(data.mpid)
                                                                        modal.find('#modifier').val(data.modifier)
            
})

//tableHeight函数
function tableHeight() {
    //可以根据自己页面情况进行调整
    return $(window).height() - 200;
}

$(function () {

    var sw = [];
    $(".js-switch").each(function (i, e) {
        sw[i] = new Switchery(e, {color: "#1AB394"})
    })
    $(window).resize(function () {
        $('#mytable').bootstrapTable('resetView', {
            height: tableHeight()
        })
    })
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        //生成用户数据
    $('#mytable').bootstrapTable({
        method: 'get',
        url: "/admin/usermp/list",
        // height:520,//高度调整
        // toolbar: '#toolbar',
        striped: true, //是否显示行间隔色
        dataField: "records",
        pagination: true,//是否分页
        queryParamsType: 'limit',
        queryParams: queryParams,
        sidePagination: 'server',
        pageNumber: 1, //初始化加载第一页，默认第一页
        pageSize: 50,//单页记录数
        pageList: [50, 100, 200, 500],//分页步进值
        showExport: true,//显示导出
        showRefresh: false,//刷新按钮
        showColumns: false,
        clikToSelect: true,//是否启用点击选中行
        // toolbarAlign:'right',
        // buttonsAlign:'right',//按钮对齐方式
        columns: [
            {
                title: '全选',
                field: 'select',
                checkbox: true,
                width: 25,
                align: 'center',
                valign: 'middle'
            },
            {
                title: 'ID',
                field: 'id',
                visible: false
            },
                                                                                                                                                                                                                                    {
                            title: '真实姓名',
                            field: 'name'
                        },
                                                                                                                                                                                                                                            {
                            title: '昵称',
                            field: 'nickName'
                        },
                                                                                                                                                                                                                {
                            title: '图像',
                            field: 'avatarPic'
                        },
                                                                                                                                                                                                                {
                            title: '地址',
                            field: 'addr'
                        },
                                                                                                                                                                                                                {
                            title: '全地址',
                            field: 'address'
                        },
                                                                                                                                                                                                                {
                            title: '语言',
                            field: 'language'
                        },
                                                                                                                                                                                                                {
                            title: '公司名称',
                            field: 'company'
                        },
                                                                                                                                                                                                                {
                            title: '部门',
                            field: 'depart'
                        },
                                                                                                                                                                                                                {
                            title: '公司logo',
                            field: 'gslogo'
                        },
                                                                                                                                                                                                                                                                        {
                            title: '公司简称',
                            field: 'gs'
                        },
                                                                                                                                                                                                                {
                            title: '职位',
                            field: 'duty'
                        },
                                                                                                                                                                                                                {
                            title: '职称',
                            field: 'zhichen'
                        },
                                                                                                                                                                                                                                                                        {
                            title: '手机号',
                            field: 'phone'
                        },
                                                                                                                                                                                                                {
                            title: '绑定网络电话',
                            field: 'tphone'
                        },
                                                                                                                                                                                                                {
                            title: '座机电话',
                            field: 'telphone'
                        },
                                                                                                                                                                                                                {
                            title: '邮箱',
                            field: 'email'
                        },
                                                                                                                                                                                                                {
                            title: 'QQ',
                            field: 'qq'
                        },
                                                                                                                                                                                                                                            {
                            title: '微信',
                            field: 'weixin'
                        },
                                                                                                                                                                                                                {
                            title: '微博',
                            field: 'weibo'
                        },
                                                                                                                                                                                                                {
                            title: '当前积分',
                            field: 'jifen'
                        },
                                                                                                                                                                                                                {
                            title: '自定义头像',
                            field: 'photo'
                        },
                                                                                                                                                                                                                                                                                                                {
                            title: '用户类型',
                            field: 'utype',
                            formatter: "utypeFormatter"
                        },
                                                                                                                                                                                                                                                                                                    {
                            title: '关联商品',
                            field: 'gids'
                        },
                                                                                                                                                                                                                {
                            title: '商品图介绍',
                            field: 'gphotos'
                        },
                                                                                                                                                                                                                {
                            title: '视频连接',
                            field: 'vedio'
                        },
                                                                                                                                                                                                                {
                            title: '音频连接',
                            field: 'audio'
                        },
                                                                                                                                                                                                                {
                            title: '个性签名',
                            field: 'signature'
                        },
                                                                                                                                                                                                                {
                            title: '维度',
                            field: 'latitude'
                        },
                                                                                                                                                                                                                {
                            title: '经度',
                            field: 'longitude'
                        },
                                                                                                                                                                                                                                                                {
                title: '操作',
                field: 'Attribute',
                align: 'center',
                width: 170,
                formatter: actionFormatter
            }
        ],
        locale: 'zh-CN',//中文支持,
    })

    //请求服务数据时所传参数
    function queryParams(params) {
        var p = {
            limit: params.limit,
            offset: params.offset,
            sort: params.sort,
            order: params.order
            , search: $('#search').val() || ""
            , status: $('#qstatus').val() || 99
        }
        return p;
    }

    $('#search_btn').click(function () {
        var p = {
            status: $('#qstatus').val(),
            search: $('#search').val(),
            ts: new Date().getTime()
        };
        $('#mytable').bootstrapTable('refresh', p);
    })

    /*
     * 验证错误提示信息高亮
     */
    $.validator.setDefaults({
        highlight: function (e) {
            $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
        }, success: function (e) {
            e.closest(".form-group").removeClass("has-error").addClass("has-success")
        }, errorElement: "span", errorPlacement: function (e, r) {
            e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
        }, errorClass: "help-block m-b-none", validClass: "help-block m-b-none"
    }), $("#aform").validate(), $("#mform").validate();
})

function checkAdd() {
    $('input:checkbox').each(function (index, item) {
        if ($(this).prop("checked")) {
            $(this).val(1);
            console.log($(this).attr("name") + "=" + $(this).val())
        } else {
            $(this).val(-1);
            console.log($(this).attr("name") + "=" + $(this).val())
        }
    });

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        return true;
}

function checkModify() {
    $('input:checkbox').each(function (index, item) {
        if ($(this).prop("checked")) {
            $(this).val(1);
            console.log($(this).attr("id") + "=" + $(this).val())
        } else {
            $(this).val(-1);
            console.log($(this).attr("id") + "=" + $(this).val())
        }
    });

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        return true;
}